<?php

/**
 * This is the model class for table "m_jadwal_pelajaran".
 *
 * The followings are the available columns in table 'm_jadwal_pelajaran':
 * @property string $id
 * @property integer $kelas_tahun_ajaran_id
 * @property integer $karyawan_id
 * @property integer $pelajaran_id
 * @property string $status
 * @property integer $hari
 * @property integer $pelajaran_ke
 * @property integer $pelajaran_sampai
 * @property integer $is_active
 * @property string $keterangan
 *
 * The followings are the available model relations:
 * @property MKaryawan $karyawan
 * @property MPelajaran $pelajaran
 * @property MJamPelajaran $pelajaranKe
 * @property MJamPelajaran $pelajaranSampai
 * @property MKelasTahunAjaran $kelasTahunAjaran
 */
class MJadwalPelajaran extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'm_jadwal_pelajaran';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('kelas_tahun_ajaran_id, karyawan_id, pelajaran_id, status, hari, pelajaran_ke, pelajaran_sampai', 'required'),
			array('kelas_tahun_ajaran_id, karyawan_id, pelajaran_id, hari, pelajaran_ke, pelajaran_sampai, is_active', 'numerical', 'integerOnly'=>true),
			array('status', 'length', 'max'=>20),
			array('keterangan', 'length', 'max'=>255),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, kelas_tahun_ajaran_id, karyawan_id, pelajaran_id, status, hari, pelajaran_ke, pelajaran_sampai, is_active, keterangan', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'karyawan' => array(self::BELONGS_TO, 'MKaryawan', 'karyawan_id'),
			'pelajaran' => array(self::BELONGS_TO, 'MPelajaran', 'pelajaran_id'),
			'pelajaranKe' => array(self::BELONGS_TO, 'MJamPelajaran', 'pelajaran_ke'),
			'pelajaranSampai' => array(self::BELONGS_TO, 'MJamPelajaran', 'pelajaran_sampai'),
			'kelasTahunAjaran' => array(self::BELONGS_TO, 'MKelasTahunAjaran', 'kelas_tahun_ajaran_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'kelas_tahun_ajaran_id' => 'Kelas Tahun Ajaran',
			'karyawan_id' => 'Karyawan',
			'pelajaran_id' => 'Pelajaran',
			'status' => 'Status',
			'hari' => 'Hari',
			'pelajaran_ke' => 'Pelajaran Ke',
			'pelajaran_sampai' => 'Pelajaran Sampai',
			'is_active' => 'Is Active',
			'keterangan' => 'Keterangan',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('kelas_tahun_ajaran_id',$this->kelas_tahun_ajaran_id);
		$criteria->compare('karyawan_id',$this->karyawan_id);
		$criteria->compare('pelajaran_id',$this->pelajaran_id);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('hari',$this->hari);
		$criteria->compare('pelajaran_ke',$this->pelajaran_ke);
		$criteria->compare('pelajaran_sampai',$this->pelajaran_sampai);
		$criteria->compare('is_active',$this->is_active);
		$criteria->compare('keterangan',$this->keterangan,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return MJadwalPelajaran the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
